#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int t, n, i, j, s, ts;

    while (scanf("%d %d", &t, &n) && t != 0) {
        char tmp[128];
        ts = 0;
        for (i = 0; i < t; i++) {
            scanf("%s %d", tmp, &s);
            ts += s;
        }

        for (i = 0; i <= n; i++) {
            for (j = 0; j <= n; j++) {
                if (3 * i + 2 * j == ts &&
                        i + j == n) {
                    printf("%d\n", j);
                    break;
                }
            }
        }
    }

    return 0;
}
